package ac.st.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class SubtitleEditor implements EntryPoint {

	private final GreetingServiceAsync greetingService = GWT
			.create(GreetingService.class);

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		final Button modifyButton = new Button("Modify");
		final TextArea sourceText = new TextArea();
		final TextArea targetText = new TextArea();
		final TextBox modifyParameter = new TextBox();
		final CheckBox addTime = new CheckBox();
		
		
		HorizontalPanel top = new HorizontalPanel();
		sourceText.setWidth("500px");
		sourceText.setHeight("200px");
		targetText.setWidth("500px");
		targetText.setHeight("200px");

		top.add(sourceText);
		top.add(targetText);
		HorizontalPanel bottom = new HorizontalPanel();
		bottom.add(addTime);
		bottom.add(modifyParameter);
		bottom.add(modifyButton);

		RootPanel.get("content").add(top);
		RootPanel.get("content").add(bottom);

		modifyButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				greetingService.greetServer(sourceText.getText(),
						modifyParameter.getText(), addTime.getValue(), new AsyncCallback<String>() {
							public void onFailure(Throwable caught) {
								targetText.setText("erreur");
							}

							public void onSuccess(String result) {
								targetText.setText(result);
							}
						});
			}

		});

	}
}
